package coollemon.kernel;

import java.util.ArrayList;

public class NormalTag implements Tag {
	private String name = "";
	private ArrayList<Contact> ref = new ArrayList<Contact>();

	private NormalTag() {}
	
	public static NormalTag createNormalTag(String name) {
		NormalTag nTag = TagManager.getNormalTag(name);
		if(nTag == null) {
			nTag = new NormalTag();
			nTag.name = name;
			TagManager.addTag(nTag);
		}
		return nTag;
	}
	
	public String getName() {
		return name;
	}
	public ArrayList<Contact> getContacts() {
		return ref;
	}
	public ContactManager getContactManager() {
		return new ContactManager(ref);
	}
	public void addContact(ContactBehave con)
	throws ClassNotMatchException {
		if(!(con instanceof Contact))
			throw new ClassNotMatchException();
		Contact c = (Contact)con;
		for(int i = 0; i < ref.size(); i++) {
			if(ref.get(i).equals(c))
				return;
		}
		ref.add(c);
	}
	public void deleteContact(ContactBehave cb)
	throws ClassNotMatchException { 
		if(!(cb instanceof Contact))
			throw new ClassNotMatchException();
		Contact con = (Contact)cb;
		ref.remove(con);
	}
}
